package com.tianshuo.factorybean.config;

import com.tianshuo.factorybean.bean.MyFactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @ClassName : CustomImportBeanDefinition
 * @Description : 模拟mybatis的bean替换过程。
 * @Author : tianshuo
 * @Date: 2020-10-26 11:18
 */
public class CustomImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

        GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
        genericBeanDefinition.setBeanClass(MyFactoryBean.class);

        registry.registerBeanDefinition("myFactoryBean",genericBeanDefinition);
    }
}

